<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('机构导入')"/>
</head>
<body style="text-align: center; margin: 30px">
    <form class="layui-form" action="">
        <div class="layui-form-item layui-form-text">
            <button style="margin: auto" type="button" class="layui-btn" id="download">
                <i class="layui-icon">&#xe601</i>下载模板
            </button>
            <button style="margin: auto" type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe681;</i>上传
            </button>
        </div>
        <div class="layui-form-item layui-form-text">
            <textarea id="msg" class="layui-textarea" style="height: 260px"></textarea>
        </div>
    </form>
</body>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    let uUrl = [[${uUrl}]];
    let dUrl = [[${dUrl}]];
    layui.use(['upload'], function () {
        var upload = layui.upload;
        $('#download').click(function () {
            $('<form id="dataForm" action="'+dUrl+'" method="get">' +  // action请求路径及推送方法
                '</form>').appendTo('body').submit().remove();
        })
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: uUrl //上传接口
            ,accept: 'file'
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            ,done: function(result){
                if (result.code == 1) {
                    layer.msg(result.msg);
                    $("#msg").val(result.msg)
                }else{
                    layer.alert("导入失败，" + result.msg)
                    $("#msg").val("导入失败，" + result.msg)
                }
                layer.closeAll('loading'); //关闭loading
            }
            ,error: function(err){
                //请求异常回调
                layer.msg("网络异常");
                layer.closeAll('loading'); //关闭loading
            }
        });
    });
</script>
</html>